package p270jp.pxv.android.detail.presentation.view;

import android.content.Context;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.View;
import android.widget.RelativeLayout;
import com.google.android.material.textview.MaterialTextView;
import java.util.List;
import p060c2.Chain;
import p064c6.Preconditions;
import p134ei.AnalyticsAction;
import p134ei.PixivAnalytics;
import p189gn.AbstractC3450p;
import p270jp.pxv.android.R;
import p270jp.pxv.android.activity.SearchResultActivity;
import p270jp.pxv.android.detail.presentation.view.TagListView;
import p270jp.pxv.android.legacy.constant.ContentType;
import p270jp.pxv.android.legacy.constant.SearchTarget;
import p270jp.pxv.android.legacy.model.PixivTag;
import p325m0.MutabilityOwnership;
import p341mg.C4859b;
import p341mg.C4860c;
import p341mg.View$OnClickListenerC4858a;
import p347mm.SearchAnalyticsUtils;
import p374nm.C5397k;
import p376no.Koin;
import p404oo.AbstractC5475a;
import p470ri.HashtagService;
import p603wm.AbstractC6949c;
import p603wm.Unit;

/* compiled from: TagListView.kt */
/* renamed from: jp.pxv.android.detail.presentation.view.TagListView */
/* loaded from: classes2.dex */
public final class TagListView extends C5397k implements AbstractC5475a {

    /* renamed from: b */
    public final int f18979b;

    /* renamed from: c */
    public final int f18980c;

    /* renamed from: d */
    public final AbstractC6949c f18981d = Preconditions.m9802P(1, new C4859b(this, null, null));

    /* renamed from: e */
    public final AbstractC6949c f18982e = Preconditions.m9802P(1, new C4860c(this, null, null));

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public TagListView(Context context, AttributeSet attributeSet) {
        super(context, attributeSet, 0);
        MutabilityOwnership.m3745m(context, "context");
        TypedValue typedValue = new TypedValue();
        if (context.getTheme().resolveAttribute(R.attr.colorCharcoalLink1, typedValue, true)) {
            this.f18979b = typedValue.data;
            TypedValue typedValue2 = new TypedValue();
            if (context.getTheme().resolveAttribute(R.attr.colorCharcoalText3, typedValue2, true)) {
                this.f18980c = typedValue2.data;
                return;
            }
            throw new IllegalStateException("Charcoal Theme, もしくは Charcoal Bridge Theme を利用してください");
        }
        throw new IllegalStateException("Charcoal Theme, もしくは Charcoal Bridge Theme を利用してください");
    }

    /* renamed from: b */
    public static void m4620b(TagListView tagListView, ContentType contentType, PixivTag pixivTag, AbstractC3450p pVar, int i, View view) {
        MutabilityOwnership.m3745m(tagListView, "this$0");
        MutabilityOwnership.m3745m(contentType, "$contentType");
        MutabilityOwnership.m3745m(pixivTag, "$tag");
        PixivAnalytics pixivAnalytics = tagListView.getPixivAnalytics();
        AnalyticsAction a = SearchAnalyticsUtils.m3538a(contentType, 4);
        MutabilityOwnership.m3746l(a, "getAnalyticsAction(conte…lyticsUtils.Location.TAG)");
        pixivAnalytics.m6527c(4, a, pixivTag.name);
        view.getContext().startActivity(SearchResultActivity.m4710e1(tagListView.getContext(), contentType, pixivTag.name, SearchTarget.EXACT_MATCH_FOR_TAGS));
        if (pVar != null) {
            pVar.invoke(Integer.valueOf(i), pixivTag);
        }
    }

    private final HashtagService getHashtagService() {
        return (HashtagService) this.f18981d.getValue();
    }

    private final PixivAnalytics getPixivAnalytics() {
        return (PixivAnalytics) this.f18982e.getValue();
    }

    /* renamed from: c */
    public final void m4619c(ContentType contentType, List<? extends PixivTag> list, AbstractC3450p<? super Integer, ? super PixivTag, Unit> pVar) {
        int i;
        int i2;
        MutabilityOwnership.m3745m(contentType, "contentType");
        MutabilityOwnership.m3745m(list, "tags");
        removeAllViews();
        int i3 = 0;
        int i4 = 0;
        for (Object obj : list) {
            int i5 = i4 + 1;
            if (i4 >= 0) {
                PixivTag pixivTag = (PixivTag) obj;
                MaterialTextView materialTextView = new MaterialTextView(getContext(), null);
                RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(-2, -2);
                if (pixivTag.translatedName == null) {
                    i = getResources().getDimensionPixelSize(R.dimen.tag_list_tag_side_margin);
                } else {
                    i = getResources().getDimensionPixelSize(R.dimen.tag_list_translated_tag_side_margin);
                }
                layoutParams.setMargins(i3, i3, i, getResources().getDimensionPixelSize(R.dimen.tag_list_tag_vertical_margin));
                materialTextView.setLayoutParams(layoutParams);
                HashtagService hashtagService = getHashtagService();
                String str = pixivTag.name;
                MutabilityOwnership.m3746l(str, "tag.name");
                materialTextView.setText(hashtagService.m2580a(str));
                materialTextView.setTextSize(2, 14.0f);
                materialTextView.setTextColor(this.f18979b);
                View$OnClickListenerC4858a aVar = new View.OnClickListener(contentType, pixivTag, pVar, i4) { // from class: mg.a

                    /* renamed from: b */
                    public final /* synthetic */ ContentType f23023b;

                    /* renamed from: c */
                    public final /* synthetic */ PixivTag f23024c;

                    /* renamed from: d */
                    public final /* synthetic */ AbstractC3450p f23025d;

                    /* renamed from: e */
                    public final /* synthetic */ int f23026e;

                    {
                        this.f23023b = r2;
                        this.f23024c = r3;
                        this.f23025d = r4;
                        this.f23026e = r5;
                    }

                    @Override // android.view.View.OnClickListener
                    public final void onClick(View view) {
                        TagListView.m4620b(TagListView.this, this.f23023b, this.f23024c, this.f23025d, this.f23026e, view);
                    }
                };
                materialTextView.setOnClickListener(aVar);
                addView(materialTextView);
                if (pixivTag.translatedName != null) {
                    MaterialTextView materialTextView2 = new MaterialTextView(getContext(), null);
                    RelativeLayout.LayoutParams layoutParams2 = new RelativeLayout.LayoutParams(-2, -2);
                    i2 = 0;
                    layoutParams2.setMargins(0, 0, getResources().getDimensionPixelSize(R.dimen.tag_list_tag_side_margin), getResources().getDimensionPixelSize(R.dimen.tag_list_tag_vertical_margin));
                    materialTextView2.setLayoutParams(layoutParams2);
                    materialTextView2.setText(pixivTag.translatedName);
                    materialTextView2.setTextSize(2, 14.0f);
                    materialTextView2.setTextColor(this.f18980c);
                    materialTextView2.setOnClickListener(aVar);
                    addView(materialTextView2);
                } else {
                    i2 = 0;
                }
                i3 = i2;
                i4 = i5;
            } else {
                Chain.m9952H();
                throw null;
            }
        }
    }

    @Override // p404oo.AbstractC5475a
    public Koin getKoin() {
        return AbstractC5475a.C5476a.m3211a(this);
    }

    public final int getTagTextColor() {
        return this.f18979b;
    }

    public final int getTranslatedTagTextColor() {
        return this.f18980c;
    }
}
